﻿using System;
using System.Collections.Generic;
using System.Text;

namespace InkjetControl.plc
{
    /// <summary>
    /// 输入继电器(X)
    /// </summary>
    public enum InputRelay
    {
        /// <summary>
        /// 本体
        /// </summary>
        X0 = 0x5000,
        /// <summary>
        /// 本体
        /// </summary>
        X77 = 0x503F,

        X10000 = 0x5100,
        X10077 = 0x513F,

        X10100 = 0x5140,
        X10177 = 0x517F,

        X10200 = 0x5180,
        X10277 = 0x51BF,

        X10300 = 0x51C0,
        X10377 = 0x51FF,

        X10400 = 0x5200,
        X10477 = 0x523F,

        X10500 = 0x5240,
        X10577 = 0x527F,

        X10600 = 0x5280,
        X10677 = 0x52BF,

        X10700 = 0x52C0,
        X10777 = 0x52FF,

        X11000 = 0x5300,
        X11077 = 0x533F,

        X11100 = 0x5340,
        X11177 = 0x539F,

        X11200 = 0x5380,
        X11277 = 0x53BF,

        X11300 = 0x53C0,
        X11377 = 0x53FF,

        X11400 = 0x5400,
        X11477 = 0x543F,

        X11500 = 0x5440,
        X11577 = 0x547F,

        X11600 = 0x5480,
        X11677 = 0x54BF,

        X11700 = 0x54C0,
        X11777 = 0x54FF,

        X20000 = 0x58D0,
        X20077 = 0x590F,

        X20100 = 0x5910,
        X20177 = 0x594F,

        X30000 = 0x5BF0,
        X30077 = 0x5C2F,
    }

    /// <summary>
    /// 输出继电器(Y)
    /// </summary>
    public enum OutputRelay
    {
        /// <summary>
        /// 本体
        /// </summary>
        Y0 = 0x6000,
        /// <summary>
        /// 本体
        /// </summary>
        Y77 = 0x603F,

        Y10000 = 0x6100,
        Y10077 = 0x613F,

        Y10100 = 0x6140,
        Y10177 = 0x617F,

        Y10200 = 0x6180,
        Y10277 = 0x61BF,

        Y10300 = 0x61C0,
        Y10377 = 0x61FF,

        Y10400 = 0x6200,
        Y10477 = 0x623F,

        Y10500 = 0x6240,
        Y10577 = 0x627F,

        Y10600 = 0x6280,
        Y10677 = 0x62BF,

        Y10700 = 0x62C0,
        Y10777 = 0x62FF,

        Y11000 = 0x6300,
        Y11077 = 0x633F,

        Y11100 = 0x6340,
        Y11177 = 0x639F,

        Y11200 = 0x6380,
        Y11277 = 0x63BF,

        Y11300 = 0x63C0,
        Y11377 = 0x63FF,

        Y11400 = 0x6400,
        Y11477 = 0x643F,

        Y11500 = 0x6440,
        Y11577 = 0x647F,

        Y11600 = 0x6480,
        Y11677 = 0x64BF,

        Y11700 = 0x64C0,
        Y11777 = 0x64FF,

        Y20000 = 0x68D0,
        Y20077 = 0x690F,

        Y20100 = 0x6910,
        Y20177 = 0x694F,

        Y30000 = 0x6BF0,
        Y30077 = 0x6C2F,
    }
    /// <summary>
    /// 辅助继电器(M,HM,SM)
    /// </summary>
    public enum AuxiliaryRelay
    {
        M0 = 0x00,

        M20479 = 0x4FFF,

        HM0 = 0xC100,

        HM6143 = 0xD8FF,

        SM0 = 0x9000,
        SM4095 = 0x9FFF,

        SEM0 = 0xC080,
        SEM127 = 0xC0FF,
    }


    /// <summary>
    /// 状态继电器(S, HS)
    /// </summary>
    public enum StatusRelay
    {
        S0 = 0x7000,
        S7999 = 0x8F3F,

        HS0 = 0xD900,
        HS999 = 0xDCEF
    }



    /// <summary>
    /// 定时器(T, HT, ET)
    /// </summary>
    public enum Timer
    {
        T0 = 0xA000,
        T4095 = 0xAFFF,

        HT0 = 0xE100,
        HT1023 = 0xE4FF,

        ET0 = 0xC000,
        ET39 = 0xC027
    }

    /// <summary>
    /// 计数器(C, HC, HSC)
    /// </summary>
    public enum Counter
    {
        C0 = 0xB000,
        C4095 = 0xBFFF,

        HC0 = 0xE500,
        HC1023 = 0xE8FF,

        HSC0 = 0xE900,
        HSC39 = 0xE927
    }

    /// <summary>
    /// 数据寄存器(D, HD, SD, HSD)
    /// </summary>
    public enum DataRegister
    {
        D0 = 0x00,
        D20479 = 0x4FFF,

        ID0 = 0x5000,
        ID99 = 0x5063,

        ID10000 = 0x5100,
        ID10099 = 0x5163,

        ID10100 = 0x5164,
        ID10199 = 0x51C7,

        ID10200 = 0x51C8,
        ID10299 = 0x522B,

        ID10300 = 0x522C,
        ID10399 = 0x528F,

        ID10400 = 0x5290,
        ID10499 = 0x52F3,

        ID10500 = 0x52F4,
        ID10599 = 0x5357,

        ID10600 = 0x5358,
        ID10699 = 0x53BB,

        ID10700 = 0x53BC,
        ID10799 = 0x541F,

        ID10800 = 0x5420,
        ID10899 = 0x5483,

        ID10900 = 0x5484,
        ID10999 = 0x54E7,

        ID11000 = 0x54E8,
        ID11099 = 0x554B,

        ID11100 = 0x554C,
        ID11199 = 0x55AF,

        ID11200 = 0x55B0,
        ID11299 = 0x5613,

        ID11300 = 0x5614,
        ID11399 = 0x5677,

        ID11400 = 0x5678,
        ID11499 = 0x56DB,

        ID11500 = 0x56DC,
        ID11599 = 0x573F,

        ID20000 = 0x58D0,
        ID20099 = 0x5933,

        ID20100 = 0x5934,
        ID20199 = 0x5997,

        ID30000 = 0x5BF0,
        ID30099 = 0x5C53,



        QD0 = 0x6000,
        QD99 = 0x6063,

        QD10000 = 0x6100,
        QD10099 = 0x6163,

        QD10100 = 0x6164,
        QD10199 = 0x61C7,

        QD10200 = 0x61C8,
        QD10299 = 0x622B,

        QD10300 = 0x622C,
        QD10399 = 0x628F,

        QD10400 = 0x6290,
        QD10499 = 0x62F3,

        QD10500 = 0x62F4,
        QD10599 = 0x6357,

        QD10600 = 0x6358,
        QD10699 = 0x63BB,

        QD10700 = 0x63BC,
        QD10799 = 0x641F,

        QD10800 = 0x6420,
        QD10899 = 0x6483,

        QD10900 = 0x6484,
        QD10999 = 0x64E7,

        QD11000 = 0x64E8,
        QD11099 = 0x654B,

        QD11100 = 0x654C,
        QD11199 = 0x65AF,

        QD11200 = 0x65B0,
        QD11299 = 0x6613,

        QD11300 = 0x6614,
        QD11399 = 0x6677,

        QD11400 = 0x6678,
        QD11499 = 0x66DB,

        QD11500 = 0x66DC,
        QD11599 = 0x673F,

        QD20000 = 0x68D0,
        QD20099 = 0x6933,

        QD20100 = 0x6934,
        QD20199 = 0x6997,

        QD30000 = 0x6BF0,
        QD30099 = 0x6C53,

        SD0 = 0x7000,
        SD4095 = 0x7FFF,

        TD0 = 0x8000,
        TD4095 = 0x8FFF,

        CD0 = 0x9000,
        CD4095 = 0x9FFF,

        ETD0 = 0xA000,
        ETD39 = 0xA027,

        HD0 = 0xA080,
        HD6143 = 0xB87F,

        HSD0 = 0xB880,
        HSD1023 = 0xBC7F,

        HTD0 = 0xBC80,
        HTD1023 = 0xC07F,

        HCD0 = 0xC080,
        HCD1023 = 0xC47F,

        HSCD0 = 0xC480,
        HSCD39 = 0xC4A7

    }


    /// <summary>
    /// FlashROM寄存器(FD, SFD, FS)
    /// </summary>
    public enum FlashROMRegister
    {
        FD0 = 0xC4C0,
        FD8191 = 0xE4BF,

        SFD0 = 0xE4C0,
        SFD4095 = 0xF4BF,

        FS0 = 0xF4C0,
        FS47 = 0xF4EF
    }

    /// <summary>
    /// 常数(B,K,H)
    /// B表示二进制
    /// K表示十进制
    /// H表示十六进制
    /// </summary>
    public enum Constant
    {
        /// <summary>
        /// B表示二进制
        /// </summary>
        B,
        /// <summary>
        /// K表示十进制
        /// </summary>
        K,
        /// <summary>
        /// H表示十六进制
        /// </summary>
        H
    }

    /*
    0：正确
    100：接收错误
    101：接收超时
    180：CRC 错误
    181：LRC 错误
    182：站号错误
    183：发送缓冲区溢出
    400：功能码错误
    401：地址错误
    402：长度错误
    403：数据错误
    404：从站忙
    405：内存错误（擦写 FLASH）
     */
    public enum ResulteCode
    {
        /// <summary>
        /// 正确
        /// </summary>
        NoError,
        /// <summary>
        /// 100 接收错误
        /// </summary>
        ReceiveError = 100,
        /// <summary>
        /// 101 接收超时
        /// </summary>
        ReceiveTimeOut,
        /// <summary>
        /// 180 CRC 错误
        /// </summary>
        CRCError = 180,
        /// <summary>
        /// 181 LRC 错误
        /// </summary>
        LRCError,
        /// <summary>
        /// 182 站号错误
        /// </summary>
        StationIDError,
        /// <summary>
        /// 183 发送缓冲区溢出
        /// </summary>
        SendBufferOverFlow,
        /// <summary>
        /// 400 功能码错误
        /// </summary>
        FuncCodeError = 400,
        /// <summary>
        /// 401 地址错误
        /// </summary>
        AddressError,
        /// <summary>
        ///  402 长度错误
        /// </summary>
        DataLengthError,
        /// <summary>
        /// 403 数据错误
        /// </summary>
        DataError,
        /// <summary>
        /// 404 从站忙
        /// </summary>
        SlaveStationBusy,
        /// <summary>
        /// 400 内存错误（擦写 FLASH）
        /// </summary>
        MemoryError
    }
}
